//
//  TimePlanTableViewCell.m
//  Run
//
//  Created by sxz on 16/4/13.
//  Copyright © 2016年 BetaTheta. All rights reserved.
//

#import "TimePlanTableViewCell.h"

@implementation TimePlanTableViewCell


- (void)setTimer:(TimeData *)timer {
    
    _timer = timer;
    
    
    if (timer.week.length == 21) {
        self.weekLabel.text = @"每日提醒";
        

    } else {
        self.weekLabel.text = [NSString stringWithFormat:@"日期: %@", timer.week];
        
    }
    self.timeLabel.text = [NSString stringWithFormat:@"时间 : %@ 点 %@ 分 ", timer.hour, timer.minte];
    
    
    self.typeLabel.text = timer.type;
    

    
    self.typeLabel.textColor = [UIColor colorWithRed:1.000 green:0.400 blue:0.400 alpha:1.000];
    
    self.clockView.frame = CGRectMake(0, 0, 5, 5);


}



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.backView = [UIImageView new];
        _backView.backgroundColor = [UIColor clearColor];
        [self.contentView addSubview:self.backView];
        
        
        self.clockView = [UIImageView new];
        [self.backView addSubview:self.clockView];
        self.clockView.contentMode = UIViewContentModeScaleAspectFill;
        

    
        
        self.weekLabel = [[UILabel alloc]initWithFrame:CGRectZero];
        _weekLabel.backgroundColor = [UIColor colorWithWhite:0.400 alpha:1.000];
        _weekLabel.textAlignment = NSTextAlignmentCenter;
        _weekLabel.adjustsFontSizeToFitWidth = YES;
        
        
        self.timeLabel = [[UILabel alloc]initWithFrame:CGRectZero];
        _timeLabel.textColor = [UIColor whiteColor];
        _timeLabel.textAlignment = NSTextAlignmentCenter;
        _timeLabel.adjustsFontSizeToFitWidth = YES;
        
        self.typeLabel = [[UILabel alloc]initWithFrame:CGRectZero];
        _typeLabel.backgroundColor = [UIColor clearColor];
        _typeLabel.textAlignment = NSTextAlignmentCenter;
        _typeLabel.adjustsFontSizeToFitWidth = YES;
        
        [self.backView addSubview:self.weekLabel];
        [self.backView addSubview:self.timeLabel];
        [self.backView addSubview:self.typeLabel];
        
    }
    return self;
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    

    
    [self.weekLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).offset(5);
        make.bottom.equalTo(self.timeLabel.mas_top).offset(-5);
        make.left.equalTo(self.clockView.mas_right).offset(5);
        make.right.equalTo(self.contentView).offset(-5);
        make.height.equalTo(self.timeLabel.mas_height);
    }];
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.height.equalTo(self.weekLabel.mas_height);
        make.top.equalTo(self.weekLabel.mas_bottom).offset(5);
        make.left.equalTo(self.clockView.mas_right).offset(100);
        make.right.equalTo (self.typeLabel.mas_left).offset(-50);
        make.bottom.equalTo(self.contentView).offset(-5);
        make.width.equalTo(self.typeLabel.mas_width).multipliedBy(3);
    }];
    
    [self.typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.timeLabel);
        make.bottom.equalTo(self.timeLabel);
        make.left.equalTo(self.timeLabel.mas_right).offset(5);
        make.right.equalTo(self.contentView).offset(-5);
        
    }];
    
    
    
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
